package com.benio.ycfdisplayer.fresco;

import android.view.View;

import com.benio.ycfdisplayer.displayer.ViewTarget;
import com.facebook.common.references.CloseableReference;
import com.facebook.imagepipeline.image.CloseableImage;

/**
 * 必须手动调用{@link CloseableViewTarget close()}方法，否则会造成内存泄露
 * Created by zhangzhibin on 2017/2/17.
 */
public abstract class CloseableViewTarget<V extends View> extends ViewTarget<V> implements CloseableBitmapTarget {

    private CloseableReference<CloseableImage> mCloseableReference;

    public CloseableViewTarget(V view) {
        super(view);
    }

    public void setCloseableReference(CloseableReference<CloseableImage> closeableReference) {
        mCloseableReference = closeableReference.cloneOrNull();
    }

    public void close() {
        CloseableReference.closeSafely(mCloseableReference);
        mCloseableReference = null;
    }
}